﻿$import( "SmitearWebGL.Core.Geometry.Rect" );

SmitearWebGL.Core.Geometry.BoundingBox = Class.extend(
{
	/******** constructor ********/

	init : function()
	{
		this._registClass( "SmitearWebGL.Core.Geometry.BoundingBox" );
		
		this._localaabb = new SmitearWebGL.Core.Geometry.Rect();
		this._worldaabb = new SmitearWebGL.Core.Geometry.Rect();
		this._viewaabb = new SmitearWebGL.Core.Geometry.Rect();
	}
	,
	getLocalAABB : function()
	{
		return this._localaabb;
	}
	,
	getWorldAABB : function()
	{
		return this._worldaabb;
	}
	,
	getViewAABB : function()
	{
		return this._viewaabb;
	}
	,
	transformRect: function( world, proj )
	{
		this._worldaabb.transform_fast( this._localaabb, world );
		this._viewaabb.transformCVV_fast( this._localaabb, proj );
	}
	,
	testRect: function( nearClip, farClip )
	{
		if ( this._viewaabb.x0 < this._viewaabb.z1 && 
			this._viewaabb.x1 > - this._viewaabb.z1 && 
			this._viewaabb.y1 > - this._viewaabb.z1 && 
			this._viewaabb.y0 < this._viewaabb.z1 && 
			this._viewaabb.z0 < farClip && 
			this._viewaabb.z1 > nearClip )
		{
			return true;
		}
		else
			return false;
	}
	,
	release : function()
	{
			this._localaabb.clear();
			this._worldaabb.clear();
			this._viewaabb.clear();
	}
}
);